package com.atguigu.guli.service.edu.service.impl;

import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.entity.query.TeacherQuery;
import com.atguigu.guli.service.edu.mapper.TeacherMapper;
import com.atguigu.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author zhaopeng
 * @since 2020-10-14
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Override
    public Page<Teacher> TeacherByCondition(Long page, Long limit, TeacherQuery teacherQuery) {
        Page<Teacher> page1 = new Page<>(page,limit);

        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();

        //判读查询条件是否为空
        if (teacherQuery==null){
            return baseMapper.selectPage(page1,wrapper);
        }

        //接收查询条件
        String joinDateBegin = teacherQuery.getJoinDateBegin();
        String joinDateEnd = teacherQuery.getJoinDateEnd();
        Integer level = teacherQuery.getLevel();
        String name = teacherQuery.getName();


        if (!StringUtils.isEmpty(name)){
            wrapper.likeRight("name",name);
        }
        if (level!=null){
            wrapper.eq("level",level);
        }

        if (!StringUtils.isEmpty(joinDateBegin)){
            wrapper.ge("join_data",joinDateBegin);
        }

        if (!StringUtils.isEmpty(joinDateEnd)){
            wrapper.le("join_date",joinDateEnd);
        }

        return baseMapper.selectPage(page1,wrapper);
    }
}
